
const util = require('../utils/util.js')
const otp = require('./otp.js')
const TOTP = otp.TOTP

const totp_gen = function (secret, timestamp) {
	var ret = new TOTP(secret, 3, 30).gen(timestamp);
	ret = { status: "success", message: "ok", data: ret };
	return util.asyncResult(ret);
}

const totp_gen2 = function (secret, timestamp) {
	var ret = new TOTP(secret, 3, 30).gen2(timestamp);
	ret = { status: "success", message: "ok", data: ret };
	return util.asyncResult(ret);
}

const totp_verify = function (secret, token) {
	var ret = new TOTP(secret, 3, 30).verify(token);
	ret = {status: "success", message: "ok", data: ret};
	return util.asyncResult(ret);
}

module.exports = {
	totp_gen: totp_gen,
	totp_gen2: totp_gen2,
	totp_verify: totp_verify,
}
